/**         Output&Input sgf files           **/
/**  properties of sgf which have been used  **/
/**  GM[1]FF[4] HA[2-9] B[] W[] SZ[19] ~AP[] **/
/**           AB[] ~AW[] KM[] RU[]           **/

#ifndef IO_SGF_H
#define IO_SGF_H

#include "go.h"

class Record;
class QString;
class QFile;
class Settings;
class QTextStream;

class IO_sgf
{
public:
    IO_sgf();
    ~IO_sgf();

    void outputSGF(QFile *file, Settings *gameSettings, Go *pcore);
    bool inputSGF(QFile *file, Settings *gameSettings, io_series *coos);

private:
    /** 基本只适用于自己程序输出的格式 **/
    /** 不支持分支, 不支持各种属性 ;( **/
    /** 文本解析器需要全部重写 **/
    /** sgf parse private functions **/
    bool sgfParseCollection(QTextStream&);
    bool sgfParseTree(QTextStream&);
    bool sgfParseNode(QTextStream&);
    bool sgfParseProperty(QTextStream&);

    bool do_HA(QTextStream&);
    bool do_KM(QTextStream&);
    bool do_RU(QTextStream&);
    bool do_GM(QTextStream&);
    bool do_FF(QTextStream&);
    bool do_AB(QTextStream&);
    bool do_SZ(QTextStream&);
    bool do_BW(QTextStream&, int color);
    bool do_Default(QTextStream&); //未加入的属性值解析则在这里处理并忽略掉
    /** sgf parse private functions **/

    /** format output sgf **/
    char o_start_tree(); // '(' in sgf
    char o_end_tree(); // ')' in sgf
    char o_start_node(); // ';' in sgf
    QString o_set_stone(int color, int x, int y); // "B[aa] or W[aa]"
    QString o_set_one_move(int color, int x, int y); // "AB[aa]/n or AW[aa]/n"
    /** format output sgf **/

    char to_coo_sgf(int); // convert (int)1-19 to (char)a-s
    int from_coo_sgf(char); //convert (char)a-s to (int)1-19

private:
    Settings *tempSettings;
    io_series *tempSeries;
    QFile *tempFile;
};

#endif // IO_SGF_H
